package com.example.demo.controller;


import com.example.demo.Student;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.PostConstruct;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.logging.Logger;

@Controller
@ResponseBody //返回数据，不要返回页面
@PropertySource(value = "application.properties", encoding ="utf-8")
public class TestController {
//这样写获取的字符串就是mytest
//    @Value("mytest")
//    private String mytest;


    //这样才能拿到 mytest的配置文件
    @Value("${mytest}")
    private String mytest;

    @Value("${mytest2}")
    private String mytest2;

    @RequestMapping("getConf")
    public String getConfig(){
        return "mytest:"+mytest+" mytest2:"+mytest2;
    }
    @RequestMapping("/user")//url路径
    public String sayHi(String name){
        //如果name为空
        if(!StringUtils.hasLength(name)){
            name="芊芊子";
        }
        return name;
    }
    @Value("${myString}")
    private String myString;

    @Value("${myString2}")
    private String myString2;

    @Value("${myString3}")
    private String myString3;

    @Autowired
    private Student student;

    @PostConstruct
    public void postConstruct(){

        System.out.println(student);
//        System.out.println("myString: "+myString);
//        System.out.println("myString2: "+myString2);
//        System.out.println("myString3: "+myString3);

    }




}
